﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Prsrp
{
    /// <summary>
    /// A placeholder enemy to test States and AI implementation.
    /// </summary>
    class Zombie : BaseEnemy
    {
        public Zombie(Vector2 _pPos)
        {
            mvSize = new Vector2(39, 42);
            mvPos = _pPos;
            miHP = miMaxHP = 3;

            LoadStates();
            LoadSprites();
        }

        public override void OnIdle()
        {
            if (EnabledTime() > 750)
            {
                SetState(EnemyState.kRunning);
                mbFlipSprite = IsHeroAtRight();
            }
        }

        public void StopZombie()
        {
            mvSpeed.X = 0;
            ResetTimer();
            SetState(BaseCharacterStates.kIdle);
        }

        public bool IsHeroAtRight()
        {
            return (Game.Engine.CurrentLevel.Characters[0].mvPos.X < mvPos.X);
        }

        public override void OnRunning()
        {
            bool bHeroIsAtRight = IsHeroAtRight();

            if (bHeroIsAtRight != mbFlipSprite)
            {
                StopZombie();
            }
            else
            {
                if (mbFlipSprite)
                {
                    mvSpeed.X = -1;
                }
                else
                {
                    mvSpeed.X = 1;
                }
            }
        }

        public override void LoadSprites()
        {
            DefineSprite(BaseCharacterStates.kIdle, "enemy1_idle", 12);
        }

        public override void Draw()
        {
            mtabStateSprites[(int)BaseCharacterStates.kIdle].Draw(mvPos, mfScale, mbFlipSprite);
        }
    }
}
